const mongoose = require("./db");
//姜思兵
const user = new mongoose.Schema({
    username: String,
    password: String,
    img:{
        type:String, //头像路径
        default:'https://tse1-mm.cn.bing.net/th/id/OIP-C.RFgnRHK1YvW7-fUS-v8L1AAAAA?w=168&h=176&c=7&r=0&o=5&dpr=1.5&pid=1.7', //默认头像路径
    }, //头像
    cid: {
        type: mongoose.Types.ObjectId,
        ref: 'role', //关联身份表
        default:"6731c354524c9c3519a9f4a3"
    },
})
const role = new mongoose.Schema({
    name: String,
    text: String,
    time: {
        type: Date,
        default: new Date()
    },
    Permissions: {
        type: [mongoose.Types.ObjectId], //关联权限表
        ref: 'Permissions' //关联权限表
    },
})

//登录人员权限表
const PermissionsSchema = new mongoose.Schema({
    Permissions_name: String, //权限名称
    Permissions_url: String, //权限url
    Permissions_level: Number, //权限等级
    pid: {
        type: mongoose.Types.ObjectId,
        ref: 'Permissions' //关联Permissions表
    }
})


const login = new mongoose.Schema({
    username: String,
    name: String,
    phone: String,
    password:String,
    pid: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "Role"
    },
    time: {
        type: Date,
        default: new Date()
    }
})
const Rolemodel = mongoose.model("Role", role, 'Role')
const Usermodel = mongoose.model("user", user, 'user')
const Loginmodel = mongoose.model("Login", login, 'Login')
const Permissionsmodel = mongoose.model("Permissions", PermissionsSchema, 'Permissions')

//翟经民

let listSchema = new mongoose.Schema({
    name: String,
    tel: String,
    sex: String,
    address: String,
    ztime: Date,
    jine:String,
    flag:Boolean
})
//专题管理
let SManagement = new mongoose.Schema({
    name: String,
    num: String,
    time: Date,
    flag: Boolean,
    content:String,
})
//广告管理
let advertisingSchema = new mongoose.Schema({
    name: String,
    img: String,
    weizhi: String,
    time: Date,
    dian:Number,
    flag: Boolean,
})
//平台管理
let platformSchema = new mongoose.Schema({
    name: String,
    time: Date,
    flag: Boolean,
})
//热词管理
let searchSchema = new mongoose.Schema({
    name: String,
    pai:String,
    time: Date,
    flag: Boolean,
})
//秒杀
let seckillSchema = new mongoose.Schema({
    name: String,
    time: Date,
    flag: Boolean,
    isshow:Boolean,
})
//拼团
let groupSchema = new mongoose.Schema({
    name: String,
    time: Date,
    flag: Boolean,
    isshow:Boolean,
})
//优惠券
let discountsSchema = new mongoose.Schema({
    name: String,
    type:String,
    shiyong:String,
    men:String,
    mian: String,
    time: Date,
    flag: Boolean,
})
//满减
let specialSchema = new mongoose.Schema({
    name: String,
    type:String,
    shiyong:String,
    men:String,
    fanwei: String,
    time: Date,
    flag: Boolean,
})

let listModel = mongoose.model("list1", listSchema,'list1')
let SManagementModel = mongoose.model("SManagement", SManagement,'SManagement')
let advertisingModel = mongoose.model("advertising", advertisingSchema,'advertising')
let platformModel = mongoose.model("platform", platformSchema,'platform')
let searchModel = mongoose.model("search", searchSchema,'search')
let seckillModel = mongoose.model("seckill", seckillSchema,'seckill')
let groupModel = mongoose.model("group", groupSchema,'group')
let discountsModel = mongoose.model("discounts", discountsSchema,'discounts')
let specialModel = mongoose.model("special", specialSchema,'special')





//申子豪

let OrderSchema = mongoose.Schema({
    cTime: {               //下单时间
        type: Date,
        default: Date.now()
    },
    source: String,        //订单来源
    status: String,        // 状态：未支付，已支付，已发货，已完成
    name: String,          //下单人姓名
    phone: String,         //下单人电话
    consignee: String,     //收货人姓名
    c_phone: String,       //收货人电话
    type: String,          //订单类型
    shopId: String,        //商品ID
    shopName: String,      //商品名称
    old_price:Number,      //原价
    price: Number,         //销售价
    num: Number            //数量
});
let AfterSaleSchema = mongoose.Schema({
    orderId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:'order'
    },                      //订单id
    name:String,            //申请售后人
    tname:String,           //自提点名称
    cate:Number,            //售后分类
    tcate:Number,           //自提点分类
});
let DeliverGoods = mongoose.Schema({
    orderId:{
        type:mongoose.Schema.Types.ObjectId,
        ref:'order'
    },                      //订单id
    driver:String,          //司机
});
let cateSchema = mongoose.Schema({
    name:String,            //分类名称
    status:Number,          //状态
},{timestamps:true})       //时间戳

let InventorySchema = mongoose.Schema({
    name:String,            //商品名称
    type:Number,            //订单分类
    delivery:Number,           //出库数量
    residue:Number,             //剩余剩余数量
    aname:String,            //申请人
},{timestamps:true})

let OrderModel = mongoose.model('order', OrderSchema, 'order');
let AfterSaleModel = mongoose.model('afterSale', AfterSaleSchema, 'afterSale');
let DeliverGoodsModel = mongoose.model('deliverGoods', DeliverGoods, 'deliverGoods');

// let ListModel = mongoose.model('list', mongoose.Schema({}), 'list');
let cateModel = mongoose.model('cate', cateSchema, 'cate');
let InventoryModel = mongoose.model('inventory', InventorySchema, 'inventory');



let ListScheam = new mongoose.Schema({
    name: String,//商品名称
    image: Array,//商品图片
    price: Number,//商品价格
    context: String,//商品描述
    sales: Number, //商品销量
    appraise: String, //商品评价
    cate:{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'cate'
    },//商品分类
    old_price:Number,//商品原价
    num:Number,//商品库存
    perpo:String,//商品人
    video:String,//商品视频
})
let ListModel = mongoose.model('list', ListScheam, 'list')

module.exports = {
    OrderModel,
    AfterSaleModel,
    DeliverGoodsModel,
    ListModel,
    cateModel,
    InventoryModel,
    Usermodel, Rolemodel, Loginmodel,Permissionsmodel,
    listModel,
    SManagementModel,
    advertisingModel,
    platformModel,
    searchModel,
    seckillModel,
    groupModel,
    discountsModel,
    specialModel,
};
